function C57_CPP_cdf_plot_MI_pvalues(Placeness_MetaData)
%% collect data for C57 saline
% C5
C5_saline_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C5_saline_MI_pvalues)
        C5_saline_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C5_saline_MI_pvalues)
        C5_saline_MI_pvalues = cat(1,C5_saline_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C5sf,C5sx,C5slow,C5shigh] = ecdf(C5_saline_MI_pvalues,'Function','cdf','Alpha',0.05);

% C6
C6_saline_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C6_saline_MI_pvalues)
        C6_saline_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C6_saline_MI_pvalues)
        C6_saline_MI_pvalues = cat(1,C6_saline_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C6sf,C6sx,C6slow,C6shigh] = ecdf(C6_saline_MI_pvalues,'Function','cdf','Alpha',0.05);

% C7
C7_saline_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C7_saline_MI_pvalues)
        C7_saline_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C7_saline_MI_pvalues)
        C7_saline_MI_pvalues = cat(1,C7_saline_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C7sf,C7sx,C7slow,C7shigh] = ecdf(C7_saline_MI_pvalues,'Function','cdf','Alpha',0.05);

% C8
C8_saline_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C8_saline_MI_pvalues)
        C8_saline_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, 'saline') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C8_saline_MI_pvalues)
        C8_saline_MI_pvalues = cat(1,C8_saline_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C8sf,C8sx,C8slow,C8shigh] = ecdf(C8_saline_MI_pvalues,'Function','cdf','Alpha',0.05);

%% Organize data for C57 saline

% get saline CDF mean
A = cat(1,C5sf,C6sf,C7sf,C8sf);
saline_F = sort(A);

% get saline CDF x-steps
B = cat(1,C5sx,C6sx,C7sx,C8sx);
saline_X = sort(B);

% get saline CDF high bound mean
C = cat(1,C5shigh,C6shigh,C7shigh,C8shigh);
saline_H = sort(C);

% get saline CDF low bound mean
D = cat(1,C5slow,C6slow,C7slow,C8slow);
saline_L = sort(D);

% Optional plotting
% % figure
% % plot(WT_saline_X, WT_saline_F, '-b', 'LineWidth', 1);
% % hold on
% % plot(WT_saline_X, WT_saline_H, '--k', 'LineWidth', 0.1);
% % hold on
% % plot(WT_saline_X, WT_saline_L, '--k', 'Linewidth', 0.1);
% % xlim([0,1])
% % ylim([0,1])
% % legend('p-WT saline','95% confidence interval','','Location','northwest')
% % hold off


%% collect data for C57 cpp1
% C5
C5_cpp1_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C5_cpp1_MI_pvalues)
        C5_cpp1_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C5_cpp1_MI_pvalues)
        C5_cpp1_MI_pvalues = cat(1,C5_cpp1_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C5sf,C5sx,C5slow,C5shigh] = ecdf(C5_cpp1_MI_pvalues,'Function','cdf','Alpha',0.05);

% C6
C6_cpp1_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C6_cpp1_MI_pvalues)
        C6_cpp1_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C6_cpp1_MI_pvalues)
        C6_cpp1_MI_pvalues = cat(1,C6_cpp1_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C6sf,C6sx,C6slow,C6shigh] = ecdf(C6_cpp1_MI_pvalues,'Function','cdf','Alpha',0.05);

% C7
C7_cpp1_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C7_cpp1_MI_pvalues)
        C7_cpp1_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C7_cpp1_MI_pvalues)
        C7_cpp1_MI_pvalues = cat(1,C7_cpp1_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C7sf,C7sx,C7slow,C7shigh] = ecdf(C7_cpp1_MI_pvalues,'Function','cdf','Alpha',0.05);

% C8
C8_cpp1_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C8_cpp1_MI_pvalues)
        C8_cpp1_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 1mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C8_cpp1_MI_pvalues)
        C8_cpp1_MI_pvalues = cat(1,C8_cpp1_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C8sf,C8sx,C8slow,C8shigh] = ecdf(C8_cpp1_MI_pvalues,'Function','cdf','Alpha',0.05);

%% Organize data for C57 cpp1

% get cpp1 CDF mean
A = cat(1,C5sf,C6sf,C7sf,C8sf);
cpp1_F = sort(A);

% get cpp1 CDF x-steps
B = cat(1,C5sx,C6sx,C7sx,C8sx);
cpp1_X = sort(B);

% get cpp1 CDF high bound mean
C = cat(1,C5shigh,C6shigh,C7shigh,C8shigh);
cpp1_H = sort(C);

% get cpp1 CDF low bound mean
D = cat(1,C5slow,C6slow,C7slow,C8slow);
cpp1_L = sort(D);


%% collect data for C57 cpp3
% C5
C5_cpp3_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C5_cpp3_MI_pvalues)
        C5_cpp3_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C5_cpp3_MI_pvalues)
        C5_cpp3_MI_pvalues = cat(1,C5_cpp3_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C5sf,C5sx,C5slow,C5shigh] = ecdf(C5_cpp3_MI_pvalues,'Function','cdf','Alpha',0.05);

% C6
C6_cpp3_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C6_cpp3_MI_pvalues)
        C6_cpp3_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C6_cpp3_MI_pvalues)
        C6_cpp3_MI_pvalues = cat(1,C6_cpp3_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C6sf,C6sx,C6slow,C6shigh] = ecdf(C6_cpp3_MI_pvalues,'Function','cdf','Alpha',0.05);

% C7
C7_cpp3_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C7_cpp3_MI_pvalues)
        C7_cpp3_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C7_cpp3_MI_pvalues)
        C7_cpp3_MI_pvalues = cat(1,C7_cpp3_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C7sf,C7sx,C7slow,C7shigh] = ecdf(C7_cpp3_MI_pvalues,'Function','cdf','Alpha',0.05);

% C8
C8_cpp3_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C8_cpp3_MI_pvalues)
        C8_cpp3_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 3mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C8_cpp3_MI_pvalues)
        C8_cpp3_MI_pvalues = cat(1,C8_cpp3_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C8sf,C8sx,C8slow,C8shigh] = ecdf(C8_cpp3_MI_pvalues,'Function','cdf','Alpha',0.05);

%% Organize data for C57 cpp3

% get cpp3 CDF mean
A = cat(1,C5sf,C6sf,C7sf,C8sf);
cpp3_F = sort(A);

% get cpp3 CDF x-steps
B = cat(1,C5sx,C6sx,C7sx,C8sx);
cpp3_X = sort(B);

% get cpp3 CDF high bound mean
C = cat(1,C5shigh,C6shigh,C7shigh,C8shigh);
cpp3_H = sort(C);

% get cpp3 CDF low bound mean
D = cat(1,C5slow,C6slow,C7slow,C8slow);
cpp3_L = sort(D);

%% collect data for C57 cpp10
% C5
C5_cpp10_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C5_cpp10_MI_pvalues)
        C5_cpp10_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_5') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C5_cpp10_MI_pvalues)
        C5_cpp10_MI_pvalues = cat(1,C5_cpp10_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C5sf,C5sx,C5slow,C5shigh] = ecdf(C5_cpp10_MI_pvalues,'Function','cdf','Alpha',0.05);

% C6
C6_cpp10_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C6_cpp10_MI_pvalues)
        C6_cpp10_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_6') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C6_cpp10_MI_pvalues)
        C6_cpp10_MI_pvalues = cat(1,C6_cpp10_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C6sf,C6sx,C6slow,C6shigh] = ecdf(C6_cpp10_MI_pvalues,'Function','cdf','Alpha',0.05);

% C7
C7_cpp10_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C7_cpp10_MI_pvalues)
        C7_cpp10_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_7') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C7_cpp10_MI_pvalues)
        C7_cpp10_MI_pvalues = cat(1,C7_cpp10_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C7sf,C7sx,C7slow,C7shigh] = ecdf(C7_cpp10_MI_pvalues,'Function','cdf','Alpha',0.05);

% C8
C8_cpp10_MI_pvalues = [];
for n = 1:size(Placeness_MetaData,2)
    if strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && isempty(C8_cpp10_MI_pvalues)
        C8_cpp10_MI_pvalues = Placeness_MetaData(n).MI_p_values;
    elseif strcmp(Placeness_MetaData(n).animalName, 'C57_8') && strcmp(Placeness_MetaData(n).drug, '(R)-CPP 10mg/kg') && strcmp(Placeness_MetaData(n).session, 'day1') && Placeness_MetaData(n).Mobility_Pass == 1 && ~isempty(C8_cpp10_MI_pvalues)
        C8_cpp10_MI_pvalues = cat(1,C8_cpp10_MI_pvalues,Placeness_MetaData(n).MI_p_values);
    end
end
[C8sf,C8sx,C8slow,C8shigh] = ecdf(C8_cpp10_MI_pvalues,'Function','cdf','Alpha',0.05);

%% Organize data for C57 cpp10

% get cpp10 CDF mean
A = cat(1,C5sf,C6sf,C7sf,C8sf);
cpp10_F = sort(A);

% get cpp10 CDF x-steps
B = cat(1,C5sx,C6sx,C7sx,C8sx);
cpp10_X = sort(B);

% get cpp10 CDF high bound mean
C = cat(1,C5shigh,C6shigh,C7shigh,C8shigh);
cpp10_H = sort(C);

% get cpp10 CDF low bound mean
D = cat(1,C5slow,C6slow,C7slow,C8slow);
cpp10_L = sort(D);


%% plot all data

figure
plot(saline_X,saline_F,'Color','#2AF598','LineWidth',3);
hold on
plot(cpp1_X,cpp1_F,'Color','#1BD7BB','LineWidth',3);
hold on
plot(cpp3_X,cpp3_F,'Color','#08B3E5','LineWidth',3);
hold on
plot(cpp10_X,cpp10_F,'Color','#003193','LineWidth',3);
hold on
xlabel('p(MI)')
ylabel('Cumulative Cell Fraction')
set(gca,'FontSize',15); 
legend('saline', '(R)-CPP 1mg/kg', '3mg/kg', '10mg/kg', 'FontSize', 15, 'Location', 'SouthEast');
% set(gca, 'Visible', 'off');
hold off

end